from PyQt5.QtWidgets import *
from PyQt5.QtGui import*
from PyQt5 import*
from PyQt5 import QtCore
from MyButton import MyButton
from SinglePlayGame import SinglePlayGame
from DoublePlayGame import DoublePlayGame
from NetWorkPlayGame import NetworkConfig
import  sys
import cgitb
cgitb.enable(format="text")
class StartWindow(QWidget):
    singlePlayGame=None
    doublePlayGame=None
    networkPlayGame=None
    def __init__(self,parent=None):
        super().__init__(parent)
        self.resize(760,650)
        self.setWindowTitle("初始界面")

        #设置背景图片
        p=QPalette(self.palette())      #调色板
        brush=QBrush(QImage("./source/五子棋界面.png"))
        p.setBrush(QPalette.Background,brush)
        self.setPalette(p)
        #设置图标
        self.setWindowIcon(QIcon("./source/icon.ico"))
        #设置固定大小
        self.setFixedSize(760,650)
        #添加按钮
        self.label1=MyButton("./source/人机对战_hover.png","./source/人机对战_press.png","./source/人机对战_normal.png",parent=self)
        self.label1.move(250,300)
        self.label2=MyButton("./source/双人对战_hover.png","./source/双人对战_press.png","./source/双人对战_normal.png",parent=self)
        self.label2.move(250,400)
        self.label3=MyButton("./source/联机对战_hover.png","./source/联机对战_press.png","./source/联机对战_normal.png",parent=self)
        self.label3.move(250,500)

        #信号和槽绑定
        self.label1.clicked.connect(self.jumpSinglePlayGame)
        self.label2.clicked.connect(self.jumpDoublePlayGame)
        self.label3.clicked.connect(self.jumpNetWorkPlayGame)

    #槽函数，跳转
    def jumpSinglePlayGame(self):
        self.close()
        self.singlePlayGame=SinglePlayGame()
        self.singlePlayGame.show()

        #返回信号绑定
        self.singlePlayGame.backSignal.connect(self.showStartWindow)
    def jumpDoublePlayGame(self):
        self.close()
        self.doublePlayGame=DoublePlayGame()
        self.doublePlayGame.show()

        self.doublePlayGame.backSignal.connect(self.showStartWindow)

    def jumpNetWorkPlayGame(self):
        #self.close()
        self.networkPlayGame=NetworkConfig(self)
        self.networkPlayGame.show()

        #self.networkPlayGame.backSignal.connect(self.showStartWindow)

    #返回显示当前界面
    def showStartWindow(self):
        if self.doublePlayGame:
            self.doublePlayGame.close()
        if self.singlePlayGame:
            self.singlePlayGame.close()
        self.show()


if __name__=="__main__":
    a=QApplication(sys.argv)
    m=StartWindow()
    m.show()
    sys.exit(a.exec_())